package a51qindian.com.comprehensive.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.li.interfaces.OnItemClickListener;

import java.util.List;

import a51qindian.com.comprehensive.R;
import a51qindian.com.comprehensive.model.ShopAdvInfo;
import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Author: Li
 * Date: 2017/9/30 0030
 * Description: 商铺广告列表适配器
 */

public class ShopAdvAdapter extends RecyclerView.Adapter<ShopAdvAdapter.ShopHolder> {


    private List<ShopAdvInfo> mShopAdvInfoList;
    private LayoutInflater mInflater;
    private OnItemClickListener mItemClickListener;

    public ShopAdvAdapter(Context context) {
        mInflater = LayoutInflater.from(context);
    }

    @Override
    public ShopHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = mInflater.inflate(R.layout.item_shop_adv, parent, false);
        final ShopHolder holder = new ShopHolder(view);
        if (mItemClickListener != null) {
            holder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    mItemClickListener.onItemClick(v, holder.getLayoutPosition());
                }
            });
        }
        return holder;
    }

    @Override
    public void onBindViewHolder(ShopHolder holder, int position) {
        ShopAdvInfo shopAdvInfo=mShopAdvInfoList.get(position);
        holder.mTxtShopAdv.setText(shopAdvInfo.getName());
    }

    @Override
    public int getItemCount() {
        return mShopAdvInfoList == null ? 0 : mShopAdvInfoList.size();
    }

    public void setShopAdvInfoList(List<ShopAdvInfo> shopAdvInfoList) {
        mShopAdvInfoList = shopAdvInfoList;
        notifyDataSetChanged();
    }

    public void setItemClickListener(OnItemClickListener itemClickListener) {
        mItemClickListener = itemClickListener;
    }

    static class ShopHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.txt_shop_adv)
        TextView mTxtShopAdv;
        public ShopHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this,itemView);
        }
    }
}
